<template>
  <div class="box">
    <div class="top">
      <h1>经贸数码商城</h1>
      <div class="imgBox">
        <div><h3>JINGMAO</h3></div>
        <h2>经贸账户</h2>
      </div>
    </div>

    <div class="loginBox">
      <form action="">
        <p class="user">
          <input
            type="text"
            v-model="username"
            placeholder="手机号/邮箱地址/账号名"
          />
        </p>
        <p class="password">
          <input type="password" v-model="password" placeholder="密码" />
        </p>

        <div class="tip">
          <a href=""><h1>短信验证码登入</h1></a>
          <a href=""><h2>忘记密码</h2></a>
        </div>

        <div class="submitBox">
          <input type="submit" value="登入" @click="loginClick()" />
        </div>
      </form>
    </div>

    <div class="loginFoot">
      <h1 align="center" class="p1" ref="p1">{{tip}}</h1>
      <a href="#" @click="loginClick1()">
        <h3>遇到问题</h3>
      </a>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      username: '',
      password: '',
      tip: ''
    }
  },
  methods: {
    loginClick () {
      // 登入判断
      if (this.username != '' && this.password != '') {
        this.request.post('/api/user', { username: this.username, password: this.password })
          .then(res => {
            console.log(res.status)
            if (res.status === 200) {
              this.tip = '登入成功'
              this.$refs.p1.style.cssText = 'opacity: 1;left: 50%'
              localStorage.setItem('token', res.token)
              localStorage.setItem('userData', res.data)
              clearTimeout(time)
              var time = setTimeout(() => {
                this.$router.push('/center')
              }, 1000)
            } else {
              this.tip = '登入失败'
              this.$refs.p1.style.cssText = 'opacity: 1;left: 50%'
              this.username = ''
              this.password = ''
            }
          })
          .catch(err => {
            console.log(err)
          })
      } else {
        this.tip = '账号密码不能为空'
        this.$refs.p1.style.cssText = 'opacity: 1;left: 50%'
      }
    },

    loginClick1 () {
      axios.get('/api/cookie1')
        .then((res) => {
          console.log(res)
        })
    }

  }
}
</script>

<style scoped>
.box {
  width: 100%;
}
.top {
  width: 100%;
}
.top h1 {
  font-size: 18px;
  color: black;
  margin: 15px;
}
.top h2 {
  font-size: 21px;
  color: black;
  margin: 10px auto;
  text-align: center;
}
.imgBox > div {
  width: 4.5rem;
  height: 4.5rem;
  background-color: rgb(89, 71, 255);
  border-radius: 10px;
  margin: 50px auto 0 auto;
}
.imgBox h3 {
  line-height: 4.5rem;
  text-align: center;
  color: aliceblue;
}
.top .imgBox {
  width: 100px;
  height: 100px;
  margin: 0 auto;
}

.loginBox {
  width: 100%;
  height: 12.5rem;
  margin: 2rem auto;
}
.user,
.password {
  width: 20rem;
  margin: 0 auto;
}
.user input {
  width: 100%;
  height: 1.5rem;
  outline: none;
  border: none;
  border-bottom: 1px solid rgb(150, 147, 147);
  background-color: transparent;
  font-size: 14px;
}
.password input {
  width: 100%;
  height: 1.5rem;
  margin: 20px auto;
  outline: none;
  border: none;
  border-bottom: 1px solid rgb(150, 147, 147);
  background-color: transparent;
  font-size: 14px;
}
.loginBox .tip {
  width: 20rem;
  height: 1.5rem;
  margin: 0 auto;
}
.loginBox a h1 {
  float: left;
  font-size: 13px;
  color: rgb(129, 173, 255);
}
.loginBox a h2 {
  float: right;
  font-size: 13px;
  color: rgb(129, 173, 255);
}
.submitBox {
  width: 20rem;
  height: 2.5rem;
  margin: 25px auto;
}
.submitBox input {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 20px;
  background-color: rgb(147, 185, 255);
  font-size: 17px;
  font-weight: 600;
  color: aliceblue;
}
.loginFoot {
  width: 100%;
  height: 200px;
  color: blue;
  position: relative;
}
.loginFoot h3 {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  color: cornflowerblue;
  font-size: 13px;
}
.loginFoot .p1{
  width: 10rem;
  line-height: 2rem;
  text-align: center;
  color: rgb(233, 55, 55);
  font-size: 14px;
  border-radius: 30px;
  position: absolute;
  left: 0;
  transform: translateX(-50%);
  opacity: 0;
  transition: all 0.5s;
}
</style>
